<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<ng-container *ngIf="state === 'hasCockpit'">
  <span mat-dialog-title>Promote the API</span>

  <mat-dialog-content class="promote__content">
    <div *ngIf="promotionTargets.length > 0; else noEnvironment">
      <gio-banner-info *ngIf="hasPromotionInProgress">
        Pending environments promotion
        <span gioBannerBody>You will be able to promote them again after they have been accepted or rejected.</span>
      </gio-banner-info>

      <gio-banner-info>
        Sharding tags
        <span gioBannerBody>For your promotion to be accepted, your API deployment tags must exist in the targeted environment.</span>
      </gio-banner-info>

      <mat-form-field class="promote__content__promotion-targets">
        <mat-label>Environment</mat-label>
        <mat-select [formControl]="promoteControl">
          <mat-option *ngFor="let target of promotionTargets" [value]="target.id" [disabled]="target.promotionInProgress">
            {{ target.name }}{{ target.promotionInProgress ? ' (pending)' : '' }}
          </mat-option>
        </mat-select>
        <mat-hint>Select the environment where you want to promote the API.</mat-hint>
      </mat-form-field>
    </div>

    <ng-template #noEnvironment>
      <gio-banner-warning>No environment is available to promote this API.</gio-banner-warning>
    </ng-template>
  </mat-dialog-content>

  <mat-dialog-actions align="end" class="actions">
    <button mat-flat-button [mat-dialog-close]="false">Cancel</button>
    <button color="primary" mat-raised-button [disabled]="promotionTargets.length === 0" (click)="onPromote()">Promote</button>
  </mat-dialog-actions>
</ng-container>

<ng-container *ngIf="state === 'meetCockpit'">
  <h2 mat-dialog-title>Meet Gravitee Cloud</h2>

  <mat-dialog-content class="meet-cockpit__content">
    <img class="meet-cockpit__content__logo" src="/assets/gravitee_cloud_logo.png" alt="Logo of Gravitee.io Cloud" />
    <p>
      <a [href]="cockpitURL" target="_blank">Gravitee Cloud</a> is a centralized, multi-tenancy tool for monitoring all your Gravitee.io
      installations from one handy interactive dashboard.
    </p>
    <p>
      Create an account on <a [href]="cockpitURL" target="_blank">Gravitee Cloud</a>, register your current installation and start promoting
      your APIs across multiple environments!`.
    </p>
  </mat-dialog-content>

  <mat-dialog-actions align="end" class="actions">
    <button mat-flat-button [mat-dialog-close]="false" data-testid="api_info_promote_ok">Ok</button>
  </mat-dialog-actions>
</ng-container>

<ng-container *ngIf="state === 'loading'">
  <h2 mat-dialog-title>Promote the API</h2>

  <mat-dialog-content class="loading__content">
    Loading...
    <mat-progress-bar mode="indeterminate"></mat-progress-bar>
  </mat-dialog-content>

  <mat-dialog-actions align="end" class="actions">
    <button mat-flat-button [mat-dialog-close]="false">Close</button>
  </mat-dialog-actions>
</ng-container>
